home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10905 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  36 lines

  1. Path: andrew.cmu.edu!mp52+
  2. From: Matthew Edward Patton <mp52+@andrew.cmu.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: template classes and destructors
  5. Date: Mon, 11 Mar 1996 00:35:01 -0500
  6. Organization: Civil and Environmental Engineering, Carnegie Mellon, Pittsburgh, PA
  7. Message-ID: <4lEvi5m00iVGA_jM06@andrew.cmu.edu>
  8. NNTP-Posting-Host: po8.andrew.cmu.edu
  9.  
  10. I have a template based class:
  11. template <class T>
  12. class foo {
  13.  T value;
  14. public:
  15.  foo() { value = (T) 0; }
  16.  foo(int size) { value = (T) 0; }
  17.  ~foo() { ::delete() };
  18. };
  19.  
  20. foo<char*>::foo(int size) { value = new char[size]; }
  21.  
  22. I need to override the default behavior of the constructors only when
  23. the type is <char*>.  That works.  The deconstructor needs to be defined
  24. only for the <char*> class, since all other types don't care.  If I
  25. don't have a destuctor I have a memory leak do I not?
  26.  
  27. I followed the same syntax as the overridden constructors and declared:
  28. foo<char*>::~foo() { delete[] value; }
  29.  
  30. This always gives me an error saying a member function 'foo' hasn't been
  31. defined for class foo<char*>.  The error is 'ridiculous' as I can point
  32. to 2 very much working constructors for class field<char*>.
  33.  
  34. Can anyone shed someight on this?  thans very much
  35.  
  36.